package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RxGroup;
import com.ruoyi.system.mapper.RxGroupMapper;
import com.ruoyi.system.service.IRxGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 后台管理员用户组Controller
 *
 * @author hjf
 * @date 2025-02-19
 */
@RestController
@RequestMapping("/hmk/group")
public class RxGroupController extends BaseController {
    @Autowired
    private IRxGroupService rxGroupService;

    @Autowired
    private RxGroupMapper rxGroupMapper;

    /**
     * 查询后台管理员用户组列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(RxGroup rxGroup) {
        startPage();
        List<RxGroup> list = rxGroupService.selectRxGroupList(rxGroup);
        return getDataTable(list);
    }

    /**
     * 导出后台管理员用户组列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:group:export')")
    //@Log(title = "后台管理员用户组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RxGroup rxGroup) {
        List<RxGroup> list = rxGroupService.selectRxGroupList(rxGroup);
        ExcelUtil<RxGroup> util = new ExcelUtil<RxGroup>(RxGroup.class);
        util.exportExcel(response, list, "后台管理员用户组数据");
    }

    /**
     * 获取后台管理员用户组详细信息
     */
    @PreAuthorize("@ss.hasPermi('hmk:group:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(rxGroupService.selectRxGroupById(id));
    }


    @PermitAll
    @GetMapping("/selectRxGroupListSimple")
    public AjaxResult selectRxGroupListSimple() {
        return success(rxGroupMapper.selectRxGroupListSimple());
    }

    /**
     * 新增后台管理员用户组
     */
    @PreAuthorize("@ss.hasPermi('hmk:group:add')")
    //@Log(title = "后台管理员用户组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RxGroup rxGroup) {
        return toAjax(rxGroupService.insertRxGroup(rxGroup));
    }

    /**
     * 修改后台管理员用户组
     */
    @PreAuthorize("@ss.hasPermi('hmk:group:edit')")
    //@Log(title = "后台管理员用户组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RxGroup rxGroup) {
        return toAjax(rxGroupService.updateRxGroup(rxGroup));
    }

    /**
     * 删除后台管理员用户组
     */
    @PreAuthorize("@ss.hasPermi('hmk:group:remove')")
    //@Log(title = "后台管理员用户组", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rxGroupService.deleteRxGroupByIds(ids));
    }
}
